package net.homelinux.chaoswg.io.renga.core.gui.operations.reader;

import net.homelinux.chaoswg.io.higherorderfunctions.AbstractUnaryFunction;
import net.homelinux.chaoswg.io.renga.core.gui.operations.visualisations.NamedBlockVisualisation;
import net.homelinux.chaoswg.io.renga.core.gui.operations.visualisations.Visualisation;

import org.jdom.Element;

public class NamedBlockVisualisationReader extends AbstractUnaryFunction<Visualisation, Element> implements VisualisationReader {

    public Visualisation apply(Element arg0) throws IllegalArgumentException {
        final int x = Integer.parseInt(arg0.getChildText("x"));
        final int y = Integer.parseInt(arg0.getChildText("y"));
        final int width = Integer.parseInt(arg0.getChildText("width"));
        final int height = Integer.parseInt(arg0.getChildText("height"));
        final String name = arg0.getChildText("name");
        
        return new NamedBlockVisualisation(x,y,width,height,name == null ? "" :name);
    }

}
